<!doctype html>
<html lang="zh-CN">

<head>
    <!-- 必须的 meta 标签 -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap 的 CSS 文件 -->
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <link rel="stylesheet" href="../css/font-awesome.min.css">

    <title>缓期申请管理:新增申请</title>
</head>

<body>

<div id="app">

    <table class="table">
        <thead>
        <tr>
            <th>延期编号</th>
            <th>学生姓名</th>
            <th>借阅卡号</th>
            <th>图书编号</th>
            <th>借阅期限</th>
            <th>延期时间</th>
            <th>提交时间</th>
            <th>申请状态</th>
            <th>是否同意</th>
        </tr>
        </thead>
        <tbody>
        <!--循环dataList里的数据，每行数据的唯一标志key-->
        <tr v-for="item in dataList" :key="item.bd_id">
            <td>{{item.bd_id}}</td>
            <td>{{item.st_name}}</td>
            <td>{{item.bob_id}}</td>
            <td>{{item.bb_id}}</td>
            <td>{{item.bd_extime}}</td>
            <td>{{item.bd_defer}}</td>
            <td>{{item.bd_time}}</td>
            <td>{{dataMap[item.bd_agree]}}</td>
            <td>
                <button type="button" class="btn btn-primary" @click="permit(item)">是</button>
                <button type="button" class="btn btn-primary" @click="ban(item)">否</button>
            </td>
        </tr>
        </tbody>
    </table>


</div>


<script src="../js/jquery-3.6.0.slim.min.js"></script>
<script src="../js/bootstrap.bundle.min.js"></script>
<script src="../js/vue.global.js"></script>
<script src="../js/axios.min.js"></script>
<script src="../js/my-axios.js"></script>
<script src="../layer/layer.js"></script>

<script>
    //定义数据
    const dataMap = {
        0: '待处理',
        1: '通过',
        2: '否决'
    }

    //定义vue应用配置
    const app = {
        //data函数专门用于定义数据
        data() {
            return {
                dataMap, //此写法等同于 dataMap : dataMap（属性名：变量名 同名）
                dataList: [],//返回列表数据
                reqList: {
                    bd_id: '',
                    st_name: '',
                    bob_id: '',
                    bb_id: '',
                    bd_extime: '',
                    bd_defer: '',
                    bd_time: '',
                    bd_agree: ''
                },
                winIdx: null,//操作窗口标识
            };
        },

        //定义方法
        methods: {
            //获取数据
            getDataList() {
                //向服务端接口http://localhost:8888/xjtu_demo_server_war_exploded/data/dataList发出get请求，Tomcat URL
                const loadIdx = layer.load();
                myAxios.get('/defer/deferList').then((response) => {
                    layer.close(loadIdx);
                    this.dataList = response.data.data;
                });
            },

            //处理执行
            permit(item) {
                this.winIdx = layer.load();
                this.reqList = item;
                myAxios.post('/defer/deferPermit', this.reqList).then(res => {
                    console.log(this.reqList);
                    layer.close(this.winIdx);
                    if (res.data.success) {
                        this.getDataList();
                        layer.msg('处理生效', {icon: 1});
                    } else {
                        layer.msg(res.data.message, {icon: 2});
                    }
                }).catch(err => {
                    layer.close(idx);
                    layer.msg('提交失败，处理未生效！', {icon: 2});
                });
            },
            ban(item) {
                this.winIdx = layer.load();
                this.reqList = item;
                myAxios.post('/defer/deferBan', this.reqList).then(res => {
                    layer.close(this.winIdx);
                    if (res.data.success) {
                        this.getDataList();
                        layer.msg('处理生效', {icon: 1});
                    } else {
                        layer.msg(res.data.message, {icon: 2});
                    }
                }).catch(err => {
                    layer.close(idx);
                    layer.msg('提交失败，处理未生效！', {icon: 2});
                });
            }
        },

        //定义回调方法：mounte 该方法在页面渲染完成立即执行
        mounted() {
            this.getDataList();
        }
    };
    Vue.createApp(app).mount('#app') //#: id
</script>

</body>

</html>